<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/inc/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="decorator" content="main" />
<title>角色管理</title>
<style type="text/css">
.textbox {
	height: 20px;
	margin: 0;
	padding: 0 2px;
	box-sizing: content-box;
}
</style>
<script type="text/javascript">
	$(document).ready(function() {
		query();

	});
	function query() {
		$('#dg').datagrid({
			url : '${ctx}/role/roleadmin.do?method=load',
			title : '角色列表',
			pagination : true,
			rownumbers : true,
			fitColumns : true,
			showFooter : true,
			striped : true,
			toolbar : '#tbtopbar',
			queryParams : {
				searchword : $("input[name='searchbox']").val(),
			},
			columns : [ [ 
			              {
				field : 'roleId',
				title : '操作',
				checkbox : true,
			} ,
			{
				field : 'roleCode',
				title : '角色编码',
				sortable : true,
				width : 100,
			}, {
				field : 'roleName',
				title : '角色名称',
				sortable : true,
				width : 100,
			}, {
				field : 'roleDescription',
				title : '角色描述',
				width : 100,
			}] ]
		});
	}

	function roleForm() {
		var info = ($('#dg').datagrid('getSelections'));
		if (info.length == 0) {
			alert("请选择具体角色进行修改");
		} else if (info.length > 1) {
			alert("您选择了" + info.length + "数据，请选择一条数据进行修改");
		} else{
			var roleid = info[0].roleId;
			var url = '${ctx}/role/roleadmin.do?method=initForm&roleid=';
			if (!isNaN(roleid)) {
				url += roleid;
			} else {
				url += 0;
			}
			window.location.href = url;
		}

	}
	
	function roleFormAdd() {
		var url = '${ctx}/role/roleadmin.do?method=addForm';
		window.location.href = url;
	}

	function delInfo() {
		var url = '${ctx}/role/roleadmin.do';
		var info = ($('#dg').datagrid('getSelections'));
		var ids = [];
		for (var i = 0; i < info.length; i++) {
			ids.push(info[i].roleId);
		};
		$.messager.confirm('确认', '您确认想要删除' + ids.length + '记录吗？', function(r) {
			if (r) {
				$.ajax({
					type : "POST",
					url : url,
					data : 'method=del&roleids=' + ids,
					success : function(dto) {
						$.messager.alert('警告', dto.msg);
						$('#dg').datagrid("reload");
					}
				});
			}
		});
	}

	function alertdia(userid) {
		var info = ($('#dg').datagrid('getSelections'));
		if (info.length > 1) {
			alert("您选择了多个角色，请选择一个角色进行配置");
		} else {
			var roleid = info[0].roleId;
			$('#dd').show();
			$('#dd').dialog({
				collapsible : true,
				minimizable : true,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '提交',
					iconCls : 'icon-ok',
					handler : function() {
						var nodes = $('#tt').tree('getChecked');
						var menuids = [];
						for ( var i = 0; i < nodes.length; i++) {
							menuids[i] = nodes[i].id;
						}
						$.ajax({
							type : "GET",
							url : '${ctx}/role/roleadmin.do?method=tijiao',
							data : "roleid=" + roleid + "&menuids=" + menuids,
							success : function(msg) {
								alert("配置成功!");
								$('#dd').dialog('close');
							}

						});
					}
				}, {
					text : '取消',
					iconCls : 'icon-cancel',
					handler : function() {
						$('#dd').dialog('close');
					}
				} ]
			});
			$('#tt').tree(
					{
						url : '${ctx}/role/roleadmin.do?method=jsontree&roleid='
								+ info[0].roleId,
						checkbox : true,
						method : 'get'
					});

		}
	}
</script>
</head>
<body>
<ul class="breadcrumbs">
		<li><a href="${ctx}/login/LoginIndexRequestServlet.do"><i class="iconfa-home"></i></a> <span
			class="separator"></span></li>
		<li>角色管理</li>
	</ul>
	<div class="maincontent">
		<div class="maincontentinner">
			<div class="row-fluid">
				<div class="span12">
					<div class="widget">
						<h4 class="widgettitle">角色管理</h4>
						<div class="widgetcontent">
							<div data-options="region:'center',title:'栏目管理'"
								style="padding: 5px; background: #eee;">
								<form id="qryFrom">
									<div id="tbtopbar" style="padding: 5px;">
										<div id="admintb" style="margin-bottom: 5px;">
											<a herf="#" class="easyui-linkbutton" iconCls="icon-add"
												plain="true" onclick="roleFormAdd()">添加</a> <a herf="#"
												class="easyui-linkbutton" iconCls="icon-remove" plain="true"
												onclick="delInfo()">删除</a> <a herf="#"
												class="easyui-linkbutton" iconCls="icon-edit" plain="true"
												onclick="roleForm()">修改</a> <a herf="#"
												class="easyui-linkbutton" iconCls="icon-edit" plain="true"
												onclick="alertdia()">配置权限</a>
										</div>
										<div id="usertb" style="padding: 0 0 5px 5px">
											<input class="textbox" name="searchbox"></input> 创建时间从：<input
												class="easyui-datebox" name="date_from"> 到：<input
												class="easyui-datebox" name="date_to"> <a herf="#"
												class="easyui-linkbutton" iconCls="icon-search" plain="true"
												onclick="query()">查询</a>

										</div>
									</div>
								</form>
								<div id="load">
									<input type="hidden" name="method" value="load" />
								</div>
								<table id="dg"></table>

								<div id="dd"
									style="display: none; padding: 5px; width: 400px; height: 500px;"
									title="角色-菜单设置">
									<ul id="tt"></ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

</body>
</html>